package com.woniuxy.enjoylife.service.impl;

import com.woniuxy.enjoylife.entity.Community;
import com.woniuxy.enjoylife.mapper.CommunityMapper;
import com.woniuxy.enjoylife.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommunityServiceImpl implements CommunityService {

    @Autowired
    private CommunityMapper communityMapper;

    /**
     * 社区是否被认证
     * @param name
     * @return
     */
    @Override
    public Community isCertification(String name) {
        return communityMapper.isCertification(name);
    }


    /**
     * 物业查看本小区，通过小区去查活动
     * @param wid
     * @return
     */
    @Override
    public Community findCommunityByWid(int wid) {
        return communityMapper.findCommunityByWid(wid);
    }

    /**
     * 查询此小区能否注册
     * @param name
     * @return
     */
    @Override
    public boolean haveCommunity(String name) {
        //判断小区名是否已存在
        if(communityMapper.haveCommunityByName(name)==null){
            //小区名不存在,可以注册
            return true;
        }else {
            //小区名已存在
            //判断小区是否已注册
            if(communityMapper.communityIsAttestation(name)==null){
                //小区已被注册，所以不能再次注册
                return false;
            }else {
                //小区没有被注册
                return true;
            }
        }
    }

    /**
     * 通过小区名查询小区id
     * @param name
     * @return
     */
    @Override
    public int findIdByName(String name) {
        return communityMapper.findIdByName(name);
    }

    /**
     * 查询用户拥有的房屋对应小区
     * @param uid
     * @return
     */
    @Override
    public List<Community> findUserCommunity(int uid) {
        return communityMapper.findUserCommunity(uid);
    }
}
